package com.zf.zfed.audit.ui

import android.view.KeyEvent
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.zf.zfed.audit.base.fragment.CustomKey

class CustomKeyViewModel : ViewModel() {

    val customKeyEvent = MutableLiveData<CustomKey>().apply {
        postValue(CustomKey.UNKNOWN)
    }

    fun onKeyDown(keyCode: Int, event: KeyEvent?) {
        if (event?.action == KeyEvent.ACTION_DOWN) {
            // 按键事件
//            ToastUtils.showLong("KeyCode: $keyCode")
            customKeyEvent.value = CustomKey.convert(keyCode)
        }

    }

    fun onKeyUp(keyCode: Int, event: KeyEvent?) {
        customKeyEvent.value = CustomKey.UNKNOWN
    }
}